﻿using Practice.PH4_2104A.DAL;
using Practice.PH4_2104A.IRepository;
using Practice.PH4_2104A.Shopping.SevenLayerFramework.Domin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice.PH4_2104A.Repository
{
    /// <summary>
    /// 订单主表的仓储实现
    /// </summary>
    public class OrderMasterRepository : IOrderMasterRepository
    {
        MyDbContext _context;

        public OrderMasterRepository(MyDbContext context)
        {
            _context = context;
        }

        //删除
        public void Delete(OrderMasterModel model)
        {
            _context.OrderMasters.Remove(model);
        }

        //查询所有
        public IQueryable<OrderMasterModel> GetAll()
        {
            return _context.OrderMasters;
        }

        //添加
        public void Insert(OrderMasterModel model)
        {
            _context.OrderMasters.Add(model);
        }

        //修改
        public void Update(OrderMasterModel model)
        {
            _context.OrderMasters.Update(model);
        }
    }


    /// <summary>
    /// 订单明细表的仓储实现
    /// </summary>
    public class OrderDetailRepository : IOrderDetailRepository
    {
        MyDbContext _context;

        public OrderDetailRepository(MyDbContext context)
        {
            _context = context;
        }

        //删除
        public void Delete(OrderDetailModel model)
        {
            _context.OrderDetails.Remove(model);
        }

        //查询所有
        public IQueryable<OrderDetailModel> GetAll()
        {
            return _context.OrderDetails;
        }

        //添加
        public void Insert(OrderDetailModel model)
        {
            _context.OrderDetails.Add(model);
        }
        //添加多条
        public void Insert(List<OrderDetailModel> model)
        {
            _context.OrderDetails.AddRange(model);
        }

        //修改
        public void Update(OrderDetailModel model)
        {
            _context.OrderDetails.Update(model);
        }
    }
}
